#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/ioport.h>


#define MEM_START_ADDR      0xFD8A0000
#define MEM_END_ADDR        0xFD8A0004
#define IRQ_NUMBER          0             // GPIO0_A0

static struct resource my_resource[] = {
    {
        .start = MEM_START_ADDR,
        .end = MEM_END_ADDR,
        .flags = IORESOURCE_MEM,
    },
    {
        .start = IRQ_NUMBER,
        .end = IRQ_NUMBER,
        .flags = IORESOURCE_IRQ,
    },
};


static void	my_platform_device_release(struct device *dev)
{
    printk(KERN_EMERG "my_platform_device_release\n");
    // 释放资源回调函数
}


static struct platform_device my_platform_device = {
    .name = "my_platform_GPIO",
    .id = -1,
    .num_resources = ARRAY_SIZE(my_resource),
    .resource = my_resource,
    .dev.release =  my_platform_device_release,
};


static int __init my_platform_device_init(void)
{   
    int ret;

    ret = platform_device_register(&my_platform_device);
    if (ret < 0)
    {
        printk(KERN_EMERG "Failed platform_device_register.\n");
        return ret;
    }

    printk(KERN_EMERG "platform_device_register OK!\n");
    return 0;
}



static void __exit my_platform_device_exit(void)
{
    platform_device_unregister(&my_platform_device);
    printk(KERN_EMERG "platform_device_unregister OK!\n");
}



module_init(my_platform_device_init);
module_exit(my_platform_device_exit);

MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Treasure1029");










